<?php
declare (strict_types = 1);
/**
 * 家
 */
namespace app\admin\controller;

use app\BaseController;
use app\common\facade\admin\HomeAdmin;
use think\exception\ValidateException;

class Home extends BaseController
{

    /**
     * 登录
     */
    public function login()
    {

        $param = $this->request->post(['name', 'password']);

        try {
            $this->validate($param, 'app\common\validate\Admin.login');
            $login = HomeAdmin::login($param);
        } catch (ValidateException $e) {
            return validateJson($e->getError());
        } catch (\Exception $e) {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson($login, '登录成功');
    }

    /**
     * 退出登录
     */
    public function loginOut()
    {

        try {
            HomeAdmin::loginOut();
        } catch (ValidateException $e) {
            return validateJson($e->getError());
        } catch (\Exception $e) {
            return exceptionJson($e->getMessage(), $e->getCode());
        }

        return successJson([], '退出登录成功');
    }

}
